<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;
/**
 * 后台分类管理控制器
 * @author Mars
 */
class GroupController extends CommonController {

    /**
     * 分类管理列表
     * @author Mars
     */
    public function index(){
        $node = M('Group');
        if(!empty($_GET['sortId'])) {
            $map = array();
          //  $map['status'] = 1;
            $map['id']   = array('in',$_GET['sortId']);
            $sortList   =   $node->where($map)->order('sort asc')->select();
        }else{
            $sortList   =   $node->order('sort asc')->select();
        }
        $this->assign("sortList",$sortList);
        $this->display();
    }

    public function add() {
           
        $this->assign('groups',M("GroupClass")->where(array('status'=>1))->select());
        $this->display();
    }
   

    public  function insert() {
            
        $model = D (CONTROLLER_NAME);

        if (false === $model->create ()) {
            $this->error ( $model->getError () );
        }

        //保存当前数据对象
        $list=$model->add ();
        if ($list!==false) { //保存成功
            $this->success ('新增成功!','__URL__',true);
        } else {
            //失败提示
            $this->error ('新增失败!','__URL__',true);
        }
    }

    

    function update() {

        $model = D ( CONTROLLER_NAME );
        if (false === $model->create ()) {
            $this->error ( $model->getError () );
        }
        // 更新数据
        $list=$model->save ();
        if (false !== $list) {
            //成功提示
            //$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
            $this->success ('编辑成功!','__URL__',true);
        } else {
            //错误提示
            $this->error ('编辑失败!','__URL__',true);
        }
    }

}
